//
//  ZSettingItemCell.m
//  Zlottery
//
//  Created by HuaYingJiTuan on 16/1/12.
//  Copyright © 2016年 张庆庆. All rights reserved.
//

#import "ZSettingItemCell.h"
#import "ZItem.h"
#import "ZItemArrow.h"
#import "ZItemSwitch.h"
#import "ZItemLabel.h"
@implementation ZSettingItemCell

//因为要创建可重用的cell

+ (instancetype)cellWithTableView:(UITableView *)tableView style:(UITableViewCellStyle)style{
    static NSString *reuseId = @"item";
    ZSettingItemCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:style reuseIdentifier:reuseId];
        cell.detailTextLabel.textColor = [UIColor grayColor];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:13];
        cell.textLabel.font = [UIFont systemFontOfSize:15];
    }
    return cell;
    
}


+ (instancetype)cellWithTableView:(UITableView *)tableView{
    return [self cellWithTableView:tableView style:UITableViewCellStyleSubtitle];
}

- (void)setItem:(ZItem *)item{
    _item = item;
    self.textLabel.text = item.title;
    if (item.icon) {
        
        self.imageView.image = [UIImage imageNamed:item.icon];
    }
    
    if (item.subTitle) {
        self.detailTextLabel.text = item.subTitle;
        
    }
    
    if ([item isKindOfClass:[ZItemArrow class]]) {
        //箭头的cell
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if([item isKindOfClass:[ZItemSwitch class]]){
        //开关的cell
        //取消cell选中的样式
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryView = [UISwitch new];
    }else if([item isKindOfClass:[ZItemLabel class]]){
        
        UILabel *timeView = [[UILabel alloc] init];
        timeView.textColor = [UIColor grayColor];
        timeView.font = [UIFont systemFontOfSize:13];
        timeView.text = item.time;
        [timeView sizeToFit];
        self.accessoryView = timeView;
    }else{
        self.accessoryView = nil;
    }
}


@end
